//
//  XSJStatusToolBar.swift
//  weiBo项目准备
//
//  Created by 鲜世杰 on 16/5/14.
//  Copyright © 2016年 鲜世杰. All rights reserved.
//

import UIKit

class XSJStatusToolBar: UIView {

    private lazy var retweetButton: UIButton = self.addClickButton("timeline_icon_retweet", title: "转发")
    
    private lazy var commentButton: UIButton = self.addClickButton("timeline_icon_comment", title: "评论")
    
    private lazy var unlikeButton: UIButton = self.addClickButton("timeline_icon_unlike", title: "赞")
    
    
    var statusViewModel : XSJStatusViewModel? {
    
        didSet {
            
            
            
            retweetButton.setTitle(statusViewModel?.retweetCountContent , forState: .Normal)
            commentButton.setTitle(statusViewModel?.commentCountContent, forState: .Normal)
            unlikeButton.setTitle(statusViewModel?.unlikeCountContent, forState: .Normal)
            
//            print(statusViewModel?.retweetCountContent)
        }
        
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func setupUI() {
    
//        backgroundColor = UIColor.redColor()
//        let retweetButton = addClickButton("timeline_icon_retweet", title: "转发")
//        let commentButton = addClickButton("timeline_icon_comment", title: "评论")
//        let unlikeButton = addClickButton("timeline_icon_unlike", title: "赞")
        let firstLineView = addChildLineView()
        let secondLineView = addChildLineView()
        
        
        retweetButton.snp_makeConstraints { (make) -> Void in
            make.leading.equalTo(self)
            make.top.equalTo(self)
            make.bottom.equalTo(self)
            make.width.equalTo(commentButton)
        }
        commentButton.snp_makeConstraints { (make) -> Void in
            make.leading.equalTo(retweetButton.snp_trailing)
            make.top.equalTo(self)
            make.bottom.equalTo(self)
            make.width.equalTo(unlikeButton)
        }
        unlikeButton.snp_makeConstraints { (make) -> Void in
            make.trailing.equalTo(self)
            make.top.equalTo(self)
            make.bottom.equalTo(self)
            make.leading.equalTo(commentButton.snp_trailing)
        }
        firstLineView.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(retweetButton.snp_trailing)
            make.centerY.equalTo(self)
        }
        secondLineView.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(commentButton.snp_trailing)
            make.centerY.equalTo(self)
        }
        
        
        
    }
    
    
    
    private func addClickButton (imageName: String, title : String) ->UIButton {
    let button = UIButton()
        button.setImage(UIImage(named: imageName), forState: .Normal)
        button.setBackgroundImage(UIImage(named: "timeline_card_bottom_background"), forState: .Normal)
        button.adjustsImageWhenHighlighted = false
        button.titleLabel?.font = UIFont.systemFontOfSize(15)
        button.setTitle(title, forState: .Normal)
        button.setTitleColor(UIColor.grayColor(), forState: .Normal)
        addSubview(button)
        return button
    }
    private func addChildLineView () -> UIView {
    
        let view = UIImageView(image: UIImage(named: "timeline_card_bottom_line"))
        addSubview(view)
        
        return view
    }
}
